extends Node3D

class_name Weapon

@export var hip_position: Vector3
@export var aim_position: Vector3
@export var vertical_recoil_spread_pos: Array[float] = [.05,.15]
@export var horizontal_recoil_spread_pos: Array[float] = [.02,.03]
@export var vertical_recoil_spread_angle: Array[float] = [-15,15]
@export var horizontal_recoil_spread_angle: Array[float] = [-15,15]
@export var recoil_kick_duration: float = .01
@export var recoil_duration: float = .5

@export var reset_speed: float = 5
@export var aim_speed: float = 5

var ready_position: Vector3
var recoil_position: Vector3
var recoil_rotation: Vector3

var can_fire = true

func _ready() -> void:
	ready_position = position
	recoil_position = position

func _process(delta: float) -> void:
	position = lerp(position, ready_position, reset_speed * delta)
	rotation = lerp(rotation, Vector3.ZERO, reset_speed * delta)

func fire() -> void:
	pass

func reload() -> void:
	pass

func recoil() -> void:
	var recoil_vertical_pos = randf_range(vertical_recoil_spread_pos[0], vertical_recoil_spread_pos[1])
	var recoil_horizontal_pos = randf_range(horizontal_recoil_spread_pos[0], horizontal_recoil_spread_pos[1])
	var recoil_vertical_angle = randf_range(vertical_recoil_spread_angle[0], vertical_recoil_spread_angle[1])
	var recoil_horizontal_angle = randf_range(horizontal_recoil_spread_angle[0], horizontal_recoil_spread_angle[1])
	position.y += recoil_vertical_pos
	position.z += recoil_horizontal_pos
	rotation.x += deg_to_rad(recoil_vertical_angle)
	rotation.y += deg_to_rad(recoil_horizontal_angle)
	#recoil_transform.rota
